import React, {Component} from 'react';
import {Popup, Tab,Button,Group,Field ,NumberPicker,SelectField, TextField,NoticeBar,CheckboxField,Dialog } from 'saltui';
import Number from  '../../room/Number'
import RoomCellHandle from  '../../form/sub/RoomCellHandle'
import RoomCellCheckIn from  '../../form/sub/RoomCellCheckIn'
import RoomCellExChange from  '../../form/sub/RoomCellExChange'
/**
 *  <CheckIn room   buttonName >
 */
export default class RHandledetail extends React.Component {
  constructor(props) {

    super(props);
    this.state = {
      prices: [],
      room: this.props.room
    };
    this.state.buttonName = this.props.buttonName;
    this.roomStatus = {
      1: 'H-room-status-undefined',
      2: 'H-room-status-readly',
      3: 'H-room-status-booked',
      4: 'H-room-status-lock',
    };

    this.className = ['room-list-right','t-R5'];
    this.className.push(this.roomStatus[this.props.room.status]);
  }

  onChange = (id, value) => {
    console.info(value);
  }

  handleTextChange = (id, value) => {
    console.info(value);
  }

  componentWillReceiveProps(nextProps){
    this.className.pop();
    this.className.push(this.roomStatus[nextProps.room.status]);
  }

  render() {

    let RoomCell ;

    switch (this.props.room.status){
      case  2:
        RoomCell =  <RoomCellHandle typeid={this.props.typeid} onChange={this.props.onChange} {...this.props.room} option={this.props.option} />;
        break;
      case  3:
        RoomCell =  <RoomCellCheckIn  isExChange={this.props.isExChange} selectToRoom={this.props.selectToRoom} exChange={this.props.exChange} typeid={this.props.typeid} onChange={this.props.onChange} {...this.props.room} option={this.props.option} />;
        break;
    }

    if(this.props.isExChange){
      let isExChange =  this.props.isExChange();
      if(isExChange && (this.props.changeRoom.from_room_id != this.props.room.id) ){
        const fromRoom = this.props.findRoom(this.props.changeRoom.from_room_id);
        RoomCell =  <RoomCellExChange  exChange={this.props.exChange} fromRoom={fromRoom}  toRoom={this.props.room } initList={this.props.onChange} typeid={this.props.typeid}  />
      }
    }


    return <div className={this.className.join(' ')} onClick={() => {
      Popup.show(RoomCell, {
        animationType: 'slide-down',
      });
    }}>
      <span>{this.props.room.room_name}</span>
      <span>{this.props.room.typeName}</span>
    </div>
  }
}
